﻿RecipeBook API:
Notation: 
	#item : RecipeBook expects a numerical value for variable 'item'.
	$item : RecipeBook expects a string value for variable 'item'.
	&item : RecipeBook expects a table value for variable 'item'.
	item : There are multiple possible data types for variable 'item'.
	[item] : Variable 'item' is optionally passed.
	
Adding RecipeBook data to your tooltip:
	RecipeBook_DoHookedFunction(tooltip, [&button]):
		* Returns nothing, but adds RecipeBook data to the indicated tooltip.
		tooltip: Either the name of or a pointer to the tooltip displaying your item's data.  Normally, this is either GameTooltip or ItemRefTooltip, unless you are doing custom tooltips.
		button: Either the name of or a pointer to the button we are currently mousing over.  This is optional, because RB will work around it.  But providing it makes things a little less process-heavy
		
	
Adding external data to RecipeBook: 
	This is designed to be helpful to those folks who would like to see RecipeBook display more than the currently-indexed data : specifically, importing data from other mods such as skilltables, vendor/trainer info for recipes, etc.
	The primary application is for adding info to the RecipeBook Browse frame.
	
	RBDB:SetMetaData(#id, #rid,  $metaID, &data) :
		* Sets the id.rid.Meta.metaID field to data (overwrites all previous data). Accepts 'nil' as &data as well. 
		* Sending 'nil' or {} as &data will erase this particular metaID.
		id: The item ID (the id of the created item) for the recipe in question.
		rid: The recipe ID (the id of the recipe as displayed in the "Tradeskill: Made Item" link) for the recipe in question.
		metaID: A string that identifies your mod as the originator of the data.
		data : A table of any sort of information you're choosing to store.

	RBDB:GetMetaData(#id, #rid, $metaID) :
		* Returns the entire contents of id.rid.Meta.metaID.  If this is blank or there is a nil value along the way (id/rid does not exist), returns {}.
		id, rid, metaID as above.

	RBDB:AppendMetaData(#id, #rid, $metaID, key, [value]) :
		* Inserts key = value into id.rid.Meta.metaID.
		id, rid, metaID as above.
		key : The key under which your data should be stored.
			* IF type(key) is a table, then iterates through that table and calls RBDB:AppendMetaData on each entry.  Therefore, entries should be in the form key = value.  It is POSSIBLE but not recommended to have entry keys also be tables, therefore recursing AppendMetaData a further time.
		value: The value to assign to field 'key'.

	RBDB:DeleteMetaData(#id, #rid, $metaID, key) :
		* Deletes the indicated key from id.rid.Meta.metaID.  
		* Returns the value/s of the deleted key/s
		id, rid, metaID as above.
		key: The key you wish to delete.
			* This will accept a table of keys in the format {key1, key2, key3} as produced by table.insert.  It will consequently return a table of values.
			
Using your external data to add sort values to RecipeBook:
	value : A string representing what we set RBOptions.Browse.Sort to.  This should be somewhat unique.  Spaces are OK.
	
	RBSkill.AddData[value] = function(&info)
		* You write a function to add any data you will need access to in the item database (see example).
			- Takes args: &info, representing the information so far.
			- Returns: &info, representing the original &info with Extra fields.
			- I reserve the following (these will all be set by the time you are passed info, so you can access them) : 
				info.Name -- Name
				info.Info -- Third column data, set after you return info.
				info.ID -- Item ID
				info.Link -- Link for the item
				info.RID -- Recipe ID
				info.RLink -- Recipe Link
				info.Diff -- Difficulty to make item
				info.Rare --The quality of the item (0-6, Poor-Artifact)
				info.iLevel  -- The Blizzard item level
				info.mLevel-- The minimum level needed for the item
				info.iType -- The item type
				info.sType -- The item subtype
				info.Loc -- The item equip location or enchant location
				info.Texture -- The texture for the item
				info.Cached -- Is the item cached?
	RBSkill.AddSort[value] = function(&itemT, &sortBy)
		* You write a function to sort the data based on whatever fields you like.
			- Takes args: 
				&itemT, representing a numerically indexed table of items.  Each item entry has the above-mentioned fields, plus any you have added.
				$sortBy, representing the value of RBOptions.Browse.Sort.
			- Returns: &itemT, representing itemT after you have sorted it.
			- You may access RBSkill:SortBy for your sort (see RBSkill:Sort entry)

	RBSkill:AddExternalSort($text, $value, $field, $header) : 
		* Creates a button on the Sort dropdown menu with display text equal to 'text'.
		* When that button is clicked: 
			- Sets RBOptions.Browse.Sort to 'value'.
			- Calls RBSkill.AddData[value] so that you can add any data values you will need to the items table.
			- Calls RBSort using the function specified by RBSkill.AddSort[value] to sort the data.
			- If 'field' is supplied, sets the contents of the third column on the item button to item.field (which we have inserted in RBSkill.AddData[value])
			- If 'header' is supplied, sets the third column header to 'header'.
		text : A string representing the displayed text on the sort dropdown.
		value : A string representing what we set RBOptions.Browse.Sort to.  This should be somewhat unique.  Spaces are OK.
		field: The identifier of the field that you have chosen for the third column display - may be nil.
		header: The text to display as the header for the third column.
			
	RBSkill:SortBy(a, b, indices, defaults, ascending) : 
		* This is designed to be called from within table.sort, so syntax is actually:
		* table.sort(&table, function(a,b) return RBSkill:SortBy(a, b, &indices, &defaults, ascending) end );
		* I anticipate you will be using itemT as the table.
		a,b : provided by table.sort
		indices : A table of indices on which to sort, in the order you wish for them to be sorted by
		defaults : A table of default values, one for each index, in case the field is blank.  Please make your defaults the same data type as your expected data, or Lua gets angry.
		ascending : A boolean value, true if you want to sort low to high, false if you want to sort high to low.
		
	
	--> This is all a little convoluted, so here's an example.
	I have an addon named "iSkill", which is tracking metadata that I want to add to RecipeBook.  Specifically, I want to be able to sort by the skill required to make an item.  iSkill knows this information.
	So, I add all the data into RecipeBook with the AddMetaData functions above, under metaID "iSkill".  I'll assume that much was clear.
	Now, I want to add the sort information.
	
	inside iSkill, I make a function called IntegrateRecipeBook().  The key portions of it go like this:
	function IntegrateRecipeBook()

		RBSkill.AddData["iSkill Skill Required"] = function(info)
			-- Let's get the data from RecipeBook's meta field instead of from iSkill's database, just to illustrate.
			local data = RBDB:GetMetaData(info.ID, info.RID, "iSkill");
			info.skillLevel = data["SkillReq"];
			-- I could add more fields here if I wanted.
			-- Make sure to return info at the end.
			return info;
		end;
		
		RBSkill.AddSort["iSkill Skill Required"] = function(itemT, sortBy)
			-- Let's do this the easy way.  Sort descending (high to low) by field 'skillLevel'.
			table.sort(itemT, function(a,b) return RBSkill:SortBy(a, b, "skillLevel", 0, false) end);
			return itemT;
		end
		-- Or you could write your own sort, however you liked.  The important thing is to return the sorted table.
		-- If you wanted to sort on skillLevel and item level (info.iLevel), you would call:
		-- table.sort(itemT, function(a,b) return RBSkill:SortBy(a, b, {"skillLevel", "iLevel"}, {0, 0}, false) end);

		RBSkill:AddExternalSort("Skill Req", "iSkill Skill Required", "skillLevel", "Skill Req");
	end;


	Other useful functions:

	RBDB:Recipe_ItemToDB(#iid, [$name]) : 
		This will convert a recipe item (i.e. "Recipe: Giant Dingo Puffs") into the appropriate created item id and recipe spell id, provided it's in the database.
		iid : The numerical item id (not itemString) of the recipe.
		name : optionally, the name of the recipe.  If GetItemInfo(iid) may return nil, then this provides a backup search string.
		returns: created item id, recipe spell id
	
	
	
	
		
		
		
	